import * as THREE from "three";

//墙面高度、厚度
const y = 3,
  z = 0.2;
export default ({ width, height }) => {
  const floor = createFloor(width, height);
  const walls = createWall(width, height);
  const roomGroup = new THREE.Group();
  roomGroup.add(floor);
  roomGroup.add(...walls);
  return roomGroup;
};
//创建地板平面
const createFloor = (width, height) => {
  const floor = new THREE.Mesh(
    new THREE.PlaneGeometry(width + 4, height + 4),
    new THREE.MeshBasicMaterial({
      color: "#1B1B33",
      side: THREE.DoubleSide
    })
  );
  floor.rotation.x = -Math.PI / 2;
  const edges = new THREE.EdgesGeometry(floor.geometry);
  const line = new THREE.LineSegments(edges, new THREE.LineBasicMaterial({ color: "#577DFF" }));
  line.layers.set(1);
  floor.add(line);
  return floor;
};

//创建墙面
const createWall = (width, height) => {
  let material = new THREE.MeshStandardMaterial({
    color: "#006AFF",
    roughness: 0, // 粗糙度
    metalness: 0, // 金属度
    blending: 1, // 混合模式
    side: 2, // 渲染哪一面
    transparent: true, // 启用透明
    opacity: 0.4 // 设置透明度 (0.0完全透明，1.0完全不透明)
  });
  //从正面开始，逆时针，创建四面墙
  const wall1 = new THREE.Mesh(new THREE.BoxGeometry(width, y, z), material);
  wall1.position.set(0, y / 2, (height + z) / 2);
  const wall2 = new THREE.Mesh(new THREE.BoxGeometry(height + z * 2, y, z), material);
  wall2.rotation.y = Math.PI / 2;
  wall2.position.set((width + z) / 2, y / 2, 0);
  const wall3 = new THREE.Mesh(new THREE.BoxGeometry(width, y, z), material);
  wall3.position.set(0, y / 2, -(height + z) / 2);
  const wall4 = new THREE.Mesh(new THREE.BoxGeometry(height + z * 2, y, z), material);
  wall4.rotation.y = Math.PI / 2;
  wall4.position.set(-(width + z) / 2, y / 2, 0);

  // roomGroup.position.set(width / 2, 0, height / 2);
  return [wall1, wall2, wall3, wall4];
};
